var app = getApp()
Page({
  data: {
    
  },
  onLoad: function (e) {
    var that = this;
    wx.getStorage({
      key: 'cardOrderInfo',
      success: function (res) {
        console.log(res.data);
        that.setData({
          orderInfo: res.data
        })
      }
    })
  },
  onShow: function () {
    var that = this;
    app.setNavtitle('订单支付');
  },
  toCancelBack:function(){//取消
    wx.navigateBack({
      delta:1
    })
  },
  toSuccessTip:function(){
    // wx.navigateTo({
    //   url: '/pages/cardPaySuccess/cardPaySuccess',
    // })
    var that = this;
    that.orderPay();
  },
  orderPay: function (e) {
    var that = this;
    var data = {};
    data.map = 'applet_pay_member_card';
    data.tid = that.data.orderInfo.tid;
    console.log(data);
    //发起请求，获取列表列表
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      mask: true,
      duration: 1000
    });
    wx.request({
      url: app.globalData.requestUrl,
      data: data,
      success: function (res) {
        if (res.data.ec == 200) {
          console.log(res.data.data);
          wx.requestPayment({
            'appId': res.data.data.appId,
            'timeStamp': res.data.data.timeStamp,
            'nonceStr': res.data.data.nonceStr,
            'package': res.data.data.package,
            'signType': res.data.data.signType,
            'paySign': res.data.data.paySign,
            'success': function (res) {
              // wx.redirectTo({
              //   url: '/pages/cardPaySuccess/cardPaySuccess?orderid=' + data.tid
              // })
              setTimeout(function () {
                wx.navigateBack({
                  delta: 4
                })
              }, 100)
            },
            'fail': function (res) {
              console.log(res);
            }
          });
        } else {
          console.log(res.data);
          app.errorTip(that, res.data.em, 2000);
        }
      },
      complete: function () {
        wx.hideToast();
      }
    });
  },
})